package com.kissoft.common.util;

import java.util.List;

import com.kissoft.mgr.model.ConfigDto;
import com.kissoft.mgr.service.ConfigService;

public class KisConfig {

	public List<ConfigDto> configs = null;
	
    private static KisConfig singleton = null;
    public KisConfig(){}
    public static KisConfig getInstance(){
		if(singleton == null) singleton = new KisConfig();
        return singleton;
	}
    
    /**
     * 키에 대한 값을 리턴한다.
     * @param key
     * @return
     */
    public String getConfigValue(ConfigService configService, String key){
    	
    	if(configs==null)this.getConfig(configService);
    	
    	String rtnValue = "";
    	int total = configs.size();
    	ConfigDto configDto = null;
    	for(int i=0; i<total; i++){
    		configDto = (ConfigDto)configs.get(i);
    		if(configDto.getKeyConfig().equals(key)){
    			rtnValue = configDto.getValueConfig();
    			break;
    		}
    	}
    	
    	return rtnValue;
    }
    
    /**
     * ks_config에서 값을 가져온다.
     */
    private void getConfig(ConfigService configService){
    	try {
			this.configs = (List<ConfigDto>)configService.getConfig();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    	
    }

    
    
	
}

